/**
 * @用法
 *  异步：
      sleep(500).then(() => {
        // 这里写sleep之后需要去做的事情
      })
    同步：
      (async function() {
        console.log('Do some thing, ' + new Date());
        await sleep(3000);
        console.log('Do other things, ' + new Date());
      })();
 */
// function sleep(time) {
//   return new Promise((resolve) => setTimeout(resolve, time));
// }

// function sleep(delay) {
//   var start = (new Date()).getTime();
//   while ((new Date()).getTime() - start < delay) {
//     continue;
//   }
// }

/**
 * 显示信息
 */
function showInfo(message, confirmText, _success) {
  wx.showModal({
    content: message,
    showCancel: false,
    confirmText: confirmText ? confirmText : '确定',
    success(res) {
      if (res.confirm) {
        _success && _success(res);
      } else if (res.cancel) {
        
      }
    }
  })
}

function showLoading() {
  wx.showLoading({
    title: '加载中',
    mask: false
  })
}

function hideLoading() {
  wx.hideLoading();
}

function confirm(_message, _success, _fail){
  wx.showModal({
    title: '',
    content: _message,
    success: function (res) {
      if (res.confirm) {
        _success && _success();
      } else if (res.cancel) {
        _fail && _fail();
      }
    }
  })
}

/**
 * 暴露接口
 */
module.exports = {
  showInfo,
  confirm,
  showLoading,
  hideLoading
};